package com.zhourh.bang.modular.edu.controller;


import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.zhourh.bang.common.persistence.dao.SResultMapper;
import com.zhourh.bang.common.persistence.model.SResult;
import com.zhourh.bang.common.support.Response;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Controller
@RequestMapping("/rule")
public class RuleController {

    private String PREFIX = "/edu/cal/";

    @Resource
    private SResultMapper resultMapper;


    @RequestMapping("")
    public String index() {
        return PREFIX + "rule.html";
    }

    @RequestMapping("queryData")
    @ResponseBody
    public Response queryData(String tag, String subject) {
        System.out.println(tag);
        System.out.println(subject);
        Wrapper<SResult> wrapper = new EntityWrapper<>();
        if (StrUtil.isNotEmpty(subject)) {
            if (StrUtil.isNotEmpty(tag) && tag.equals("next")) {
                wrapper.like("next", subject);
            } else {
                wrapper.like("prev", subject);
            }
            return Response.success().list(resultMapper.selectList(wrapper));
        }
        return Response.success();

    }

}
